package routers

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"xl_api/routers/middleware"
)

func InitRouter() *gin.Engine {
	router := gin.New()

	router.Use(gin.Logger())
	router.Use(middleware.CorsMW())
	router.Use(middleware.LoggerMW())
	router.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusNotFound, gin.H{
			"code": 404,
			"msg":  "找不到该路由",
		})
		return
	})

	router.NoMethod(func(c *gin.Context) {
		c.JSON(http.StatusNotFound, gin.H{
			"code": 404,
			"msg":  "找不到该方法",
		})
		return
	})

	RegisterApiRouter(router)

	return router
}
